package com.example.springboot.web;

import com.example.springboot.model.Student;
import com.example.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentController {


    @Autowired
    private StudentService service;


    @RequestMapping(value = "/student")
    public @ResponseBody Object student() {

        Student student = service.queryStudentById(1);

        return student;
    }


    @RequestMapping(value = "/add")
    public  @ResponseBody Object addStudent() {

        int count = 0;

        try {
            Student student = new Student();
            student.setId(66);
            student.setName("abc");
            student.setAge(20);

            count = service.addStudent(student);
        } catch (Exception e) {
            e.printStackTrace();

            return "fail";
        }


        return count;
    }


}
